#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <glob.h>

#include "medialib.h"
#include "mytbf.h"

#define PATHSIZE (1024)

struct channel_context_st{
    chnid_t chnid;
    char *desc;
    glob_t mp3glob;
    int pos;
    int fd;
    off_t offset;
    mytbf_t *tbf;
};

static struct channel_context_st channel[MAXCHNID + 1];

int mlib_getchnlist(struct mlib_listentry_st **result, int *resnum)
{
    char path[PATHSIZE] = {0};
    glob_t globres;
    int num = 0;
    struct mlib_listentry_st *ptr;
    struct channel_context_st *res;
    for(i = 0; i < MAXCHNID + 1; i++)
    {
        channel[i].chnid = -1;
    }

    snprintf(path, PATHSIZE, "%s/*", server_conf.media_dir);
    if(glob(path, 0, NULL, &globres)){ return -1; }
    for(i = 0; i < globres.gl_pathc; i++)
    {
        path2entry(globres.gl_pathv[i]);
        num++;
    }

    if(!(ptr = malloc(sizeof(struct msg_listentry_st) * globres.gl_pathc))){ syslog(LOG_ERR, "malloc() error"); return -2; }
    *result =
    *resnum = num;

    return 0;
}

int mlib_freechnlist(struct mlib_listentry_st *)
{
}

int mlib_readchn(chnid_t , void *, size_t)
{
}
